package com.bookocean.infrastructure.persistence.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bookocean.domain.repository.DailyQuoteRepository;
import com.bookocean.infrastructure.persistence.mapper.DailyQuoteMapper;
import com.bookocean.infrastructure.persistence.po.DailyQuotePO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * 每日一句仓储实现类
 * 
 * @author gaoxing
 * @since 2025-08-16
 */
@Repository
@RequiredArgsConstructor
public class DailyQuoteRepositoryImpl implements DailyQuoteRepository {

    private final DailyQuoteMapper dailyQuoteMapper;

    @Override
    public DailyQuotePO findByQuizId(Long quizId) {
        LambdaQueryWrapper<DailyQuotePO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DailyQuotePO::getId, quizId);
        return dailyQuoteMapper.selectOne(wrapper);
    }

    @Override
    public DailyQuotePO save(DailyQuotePO dailyQuote) {
        dailyQuoteMapper.insert(dailyQuote);
        return dailyQuote;
    }

    @Override
    public Long getCount() {
        return dailyQuoteMapper.selectCount(null);
    }
}
